package com.softcomputer.rpt.ejb;

import com.softcomputer.rpt.entity.LogMessage;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

@MessageDriven(mappedName = "jms/NotificationQueue", activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class NotificationBean implements MessageListener {

    public NotificationBean() {
    }

    @Override
    public void onMessage(Message message) {
        {
            try {
                Object msgObj = ((ObjectMessage) message).getObject();
                if (msgObj != null) {
                }
                {
                    LogMessage logMessage = (LogMessage) msgObj;
                    System.out.println("Message updated:");
                    StringBuilder sb = new StringBuilder();
                    sb.append("Message ID=");
                    sb.append(logMessage.getId());
                    sb.append(", ");
                    sb.append("text=");
                    sb.append(logMessage.getMessage());
                    System.out.println(sb.toString());
                }
            } catch (JMSException ex) {
                Logger.getLogger(NotificationBean.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
